# -*- coding: utf-8 -*-
"""
Created on Wed Dec 29 19:45:42 2021

@author: Administrator
"""

import pandas as pd
import numpy as np
import os
import re

path = r'C:\Users\Administrator\Desktop\123'
os.chdir(path)

with open('ExternalENodeBFunction.log') as f:
    content = f.read()

    p1 = r'(=+\s.+\s=+\s(.+\s){28})'
    pattern1 = re.compile(p1)

    res = re.findall(pattern1,content)
    res = [x[0] for x in res]

enb = []
mcc = []
mnc = []
external = []
for x in res:
    p1 = r'eNBId.+'
    pattern1 = re.compile(p1)
    enb.append(re.findall(pattern1,x)[0].split()[1])
    p2 = r' >>> 1.mcc =.+'
    pattern2 = re.compile(p2)
    mcc.append(re.findall(pattern2,x)[0].split('=')[1])
    p3 = r' >>> 2.mnc = .+'
    pattern3 = re.compile(p3)
    mnc.append(re.findall(pattern3,x)[0].split('=')[1])
    p4 = r'externalENodeBFunctionId.+'
    pattern4 = re.compile(p4)
    external.append(re.findall(pattern4,x)[0].split()[1])

df = pd.DataFrame({
        'enb':enb,
        'mcc':mcc,
        'mnc':mnc,
        'external':external,
        })

with pd.ExcelWriter('456.xlsx') as f:
    df.to_excel(f, index =False)

